
const app = getApp();
const MyInfomation = require('../../mySelfData/myInfomation.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    CLIENTHEADER: 'https://mmbiz.qpic.cn/mmbiz_png/cPqRMAOFRTKGAGZA0E43LFtrF1NicLFNzIPVIOEYPYaKyJA9w8SQMeH1YNrmE5MUaUbLK69494fPCRAKaxPtWkA/0?wx_fmt=png',
    customHeight: app.globalData.CustomBar,
    mainPageSize: {
      Dheight: 0,
      Dwidth: 0
    },
    rpx: 0.1,
    animation: '',
    bar: false,
    BasicInformation: MyInfomation.BasicInfo,
    EmploymentInfomation: MyInfomation.EmployInfo,
    modalName: ' ',
    ExperienceInfomation:  MyInfomation.ExperInfo,
    ExperModelConfig: '',
    ProductInfomation: MyInfomation.ProInfo,
    experienceId: 0,
    experDrawerPosition: 0,
    ProModelConfig: '',
    ProShowIndex: 0,
    HomePageUrl: MyInfomation.homePageUrl,
    usernameClassList: [],
    posterLineTextShow: 'noshow',
    posterLineLineShow: 'noshow'
  },

  toggle(e) {
    console.log(e);
    if(this.data.bar) {
      this.setData({
        bar: false
      })
    } else {
      this.setData({
        bar: true
      })
    }
    var anmiaton = e.currentTarget.dataset.class;
    var that = this;
    that.setData({
      animation: anmiaton
    })
    setTimeout(function() {
      that.setData({
        animation: ''
      })
    }, 1000)
    console.log(this.data.animation)
  },

  handleHeader(e) {
    this.setData({
      modalName: e.currentTarget.dataset.target
    })
    this.setData({
      BasicInformation: app.globalData.userInformation,
      EmploymentInfomation: app.globalData.userEmploymentInfomation
    })
  },
  hideModal() {
    this.setData({
      modalName: ''
    })
  },

  showExperience(e) {
    console.log('点击抽屉框')
    this.setData({
      ExperModelConfig: 'show',
      experienceId: e.currentTarget.dataset.experid,
      experDrawerPosition: 0
    })
  },

  experHideModal() {
    this.setData({
      ExperModelConfig: ''
    })
  },
  // towerSwiper
  // 初始化towerSwiper
  towerSwiper(name) {
    let list = this.data[name];
    for (let i = 0; i < list.length; i++) {
      list[i].zIndex = parseInt(list.length / 2) + 1 - Math.abs(i - parseInt(list.length / 2))
      list[i].mLeft = i - parseInt(list.length / 2)
    }
    this.setData({
      ProductInfomation: list,
      swiperListLength: parseInt(list.length/2) + 1
    })
    console.log()
  },
  // towerSwiper触摸开始
  towerStart(e) {
    this.setData({
      towerStart: e.touches[0].pageX
    })
  },
  // towerSwiper计算方向
  towerMove(e) {
    this.setData({
      direction: e.touches[0].pageX - this.data.towerStart > 0 ? 'right' : 'left'
    })
  },
  // towerSwiper计算滚动
  towerEnd(e) {
    let direction = this.data.direction;
    let list = this.data.ProductInfomation;
    if (direction == 'right') {
      let mLeft = list[0].mLeft;
      let zIndex = list[0].zIndex;
      for (let i = 1; i < list.length; i++) {
        list[i - 1].mLeft = list[i].mLeft
        list[i - 1].zIndex = list[i].zIndex
      }
      list[list.length - 1].mLeft = mLeft;
      list[list.length - 1].zIndex = zIndex;
      this.setData({
        ProductInfomation: list
      })
    } else {
      let mLeft = list[list.length - 1].mLeft;
      let zIndex = list[list.length - 1].zIndex;
      for (let i = list.length - 1; i > 0; i--) {
        list[i].mLeft = list[i - 1].mLeft
        list[i].zIndex = list[i - 1].zIndex
      }
      list[0].mLeft = mLeft;
      list[0].zIndex = zIndex;
      this.setData({
        ProductInfomation: list
      })
    }
  },
  towerIndex(e) {
    console.log('点击轮播图弹出框')
    this.setData({
      ProShowIndex: e.currentTarget.dataset.index
    })
  },

  watchLgImg(e) {
    const urlList = this.data.experienceData.experList[e.currentTarget.dataset.experid].companyWorkImg
    console.log(urlList);
    wx.previewImage({
      current: urlList[e.currentTarget.dataset.id],
      urls: urlList
    })
  },
  watchProLgImg(e) {
    const urlList = this.data.ProductInfomation[e.currentTarget.dataset.proid].productImageList
    wx.previewImage({
      current: urlList[e.currentTarget.dataset.id],
      urls: urlList
    })
  },

  productModelShow() {
    this.setData({
      ProModelConfig: 'show',
    })
  },

  productModelHide() {
    this.setData({
      ProModelConfig: ''
    })
  },
  navigatorURL(e) {
    wx.getUserInfo({
      success: function(res) {
        console.log(res)
        let UserInfo = res.userInfo
        wx.navigateTo({
          url: e.currentTarget.dataset.navurl,
          success: (res) => {
            res.eventChannel.emit('acceptDataFromOpenerPage', {clientName: UserInfo.nickName, clientAvatar: UserInfo.avatarUrl})
          }
        })
      }
    })
  },
  testlist: ['1','2'],
  usernameList: [],

  copyText() {
    wx.setClipboardData({
      data: 'https://gitee.com/kai_kai_cai/WechatWebResume',
      success (res) {
        wx.getClipboardData({
          success (res) {
            console.log(res.data) // data
          }
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    this.setData({
      testmodel: options.userShareName
    })
    
    this.towerSwiper('ProductInfomation')

    for(let i = 0; i < this.data.BasicInformation.userName.length; i++) {
      this.usernameList[i] = 'noshow'
    }
    this.setData({
      usernameClassList: this.usernameList
    })
    
  },

  onPageScroll(e) {
    if(e.detail.scrollTop > 200) {
      this.setData({
        bar: true
      })
    } else {
      this.setData({
        bar: false
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    const that = this
    wx.getSystemInfo({
      success: function (res) {
        // 高度,宽度 单位为px
        // 这里为了让误差变小，所以计算RPX比例的时候为50倍计算
        // console.log(750 / res.windowWidth)
        that.setData({
          mainPageSize: {
            Dheight: res.windowHeight,
            Dwidth: res.windowWidth
          },
          rpx: 750 / res.windowWidth
        })
      }
    })

    for(let i = 0; i < this.data.BasicInformation.userName.length; i++) {
      setTimeout(() => {
        this.usernameList[i] = ''
        this.setData({
          usernameClassList: this.usernameList
        })
      }, 200 * i)
    }
    setTimeout(() => {
      this.setData({
        posterLineLineShow: ''
      })
    }, 200 * this.data.BasicInformation.userName.length + 500)

    setTimeout(() => {
      this.setData({
        posterLineTextShow: ''
      })
    }, 200 * this.data.BasicInformation.userName.length + 500 + 250)

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})